{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-title">
				<h5>客户管理</h5>
				<button style="float:right; margin-top:-10px;" title="刷新页面" type="button" class="btn btn-default btn-outline" onclick="window.location.reload()" id="">
					<i class="fa fa-refresh"></i>
				</button>
			</div>
			<div class="ibox-content">
				<div class="row row-lg">
					<div class="col-sm-12">
						<div class="row" id="searchGroup">
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">编号</button>
									</div>
									<input type="text" class="form-control" id="id" placeholder="编号" />
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">身份证</button>
									</div>
									<input type="text" class="form-control" id="id_card" placeholder="身份证" />
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">姓名及其他</button>
									</div>
									<input type="text" class="form-control" id="first_name" placeholder="姓名" />
								</div>
							</div>
							<!--<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">姓</button>
									</div>
									<input type="text" class="form-control" id="last_name" placeholder="姓" />
								</div>
							</div>-->

							<script src="__PUBLIC__/static/js/plugins/shengshiqu/distpicker.data.js"></script>
							<script src="__PUBLIC__/static/js/plugins/shengshiqu/distpicker.js"></script>
							<script src="__PUBLIC__/static/js/plugins/shengshiqu/main.js"></script>
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">出生年</button>
									</div>
									<input type="text" autocomplete="off" placeholder="出生年" class="form-control layer-date"  id="birth_year">
								</div>
							</div>

							<!-- search end -->
							<div class="col-sm-2">
									<button type="button" class="btn btn-primary " onclick="CodeGoods.search()" id="">
										<i class="fa fa-search"></i>&nbsp;搜索
									</button>
							</div>
						</div>
						<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">
							{if condition="in_array('/admin/stepone/status',session('admin.nodes')) || session('admin.role') eq 1"}
							<button type="button" id="export" class="btn btn-primary button-margin" onclick="CodeGoods.export()">
								<i class="glyphicon glyphicon-export"></i>&nbsp;批量导出请款单
							</button>
							{/if}
						</div>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};

	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
 			{title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
			{title: '身份证', field: 'id_card', visible: true, align: 'center', valign: 'middle'},
			// {title: '身份证图', field: 'idcardimg', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.idCardFormatter},
 			{title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle'},
			{title: '生日', field: 'birth_day', visible: true, align: 'center', valign: 'middle'},
			// {title: '电话', field: 'mobile', visible: true, align: 'center', valign: 'middle'},
			// {title: '送件日期', field: 'deliver_time', visible: true, align: 'center', valign: 'middle'},
			// {title: '电话', field: 'mobile', visible: true, align: 'center', valign: 'middle'},
			{title: '通知书受理编号', field: 'tzsslbh', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.tzsslbhFormatter},
 			// {title: '更名', field: 'is_rename', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.isNotFormatter},
 			// {title: '银行本代管', field: 'is_yhb_dg', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.isNotFormatter},
 			// {title: '护照代管', field: 'is_hz_dg', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.isNotFormatter},
 			// {title: '介绍人', field: 'introducer', visible: true, align: 'center', valign: 'middle'},
 			// {title: '承办人', field: 'director', visible: true, align: 'center', valign: 'middle'},
 			// {title: '承办人电话', field: '', visible: true, align: 'center', valign: 'middle'},
 			{title: '工作年月', field: 'work_year_month', visible: true, align: 'center', valign: 'middle'},
 			{title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle',formatter: 'CodeGoods.buttonFormatter'},
 		];
 	};

	CodeGoods.buttonFormatter = function(value,row,index) {
		if(value){
			var str= '';
			str += '<button type="button" class="btn btn-success btn-xs" title="修改"  onclick="CodeGoods.update('+value+')"><i class="fa fa-pencil"></i>&nbsp;修改</button>&nbsp;'
			str += '<button type="button" class="btn btn-danger btn-xs" title="删除"  onclick="CodeGoods.delete('+value+')"><i class="fa fa-trash"></i>&nbsp;删除</button>&nbsp;'
			str += '<button type="button" class="btn btn-info btn-xs" title="请款单"  onclick="CodeGoods.qingkuan('+value+')"><i class="fa fa-eye"></i>&nbsp;请款单</button>&nbsp;'
			str += '<button type="button" class="btn btn-danger btn-xs" title="护照"  onclick="CodeGoods.view('+value+')"><i class="fa fa-trash"></i>&nbsp;查看护照</button>&nbsp;'
			/*str += '<button type="button" class="btn btn-danger btn-xs" title="查看"  onclick="CodeGoods.view('+value+')"><i class="fa fa-trash"></i>&nbsp;查看</button>&nbsp;'*/
			return str;
		}
	}

	CodeGoods.isNotFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">是</span>';
				break;
				case '2':
					return '<span class="label label-warning">否</span>';
				break;
			}
		}
	}

	CodeGoods.tzsslbhFormatter = function(value,row,index) {
		return '<input type="text" id="tzsslbh'+row.id+'" class="form-control" value="'+value+'" onblur="tzsbhEdit('+row.id+')"/>';
	}
	tzsbhEdit = function(value) {
		let tzsbh = $('#tzsslbh'+value).val();
		var ajax = new $ax(Feng.ctxPath + "/overdue/update", function (data) {
			if ('00' === data.status) {
				Feng.success(data.msg);
				//CodeGoods.table.refresh();
			} else {
				Feng.error(data.msg);
			}
		});
		ajax.set('tzsslbh', tzsbh);
		ajax.set('id',value);
		ajax.start();
	}

	CodeGoods.view = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '查看护照',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/overdue/view?id='+value});
		}
	}

	CodeGoods.idCardFormatter = function(value,row,index) {
		var reg = RegExp(/|/);
		if(value.match(reg)){
			strs = value.split("|");
		}
		var img = '';
		//console.log(strs)
		for (i=0;i<strs.length ;i++ )
		{
			img = img + "<a href=\"javascript:void(0)\" onclick=\"previewImg('"+strs[i]+"')\"><img height='50' src="+strs[i]+"></a>";
		}
		if(img){
			return img;
		}
	}

	CodeGoods.amountFormatter = function(value,row,index) {
		if(value){
			return '<span class="label label-info">'+value+'</span>';
		}
	}

	CodeGoods.statusFormatter = function(value,row,index) {
		if(value !== null){
			if(value == 1){
				return '<input class="mui-switch mui-switch-animbg status'+row.id+'" type="checkbox" onclick="CodeGoods.updatestatus('+row.id+',0)" checked>';
			}else{
				return '<input class="mui-switch mui-switch-animbg status'+row.id+'"  type="checkbox" onclick="CodeGoods.updatestatus('+row.id+',1)">';
			}
		}
	}

	CodeGoods.create_timeFormatter = function(value,row,index) {
		if(value){
			return formatDateTime(value);
		}
	}

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['id'] = $("#id").val();
		queryData['id_card'] = $("#id_card").val();
		queryData['first_name'] = $("#first_name").val();
		queryData['birth_year'] = $("#birth_year").val();
		queryData['last_name'] = $("#last_name").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.status = function (value) {
		if (this.check()) {
			var idx = '';
			$.each(CodeGoods.seItem, function() {
				idx += ',' + this.id;
			});
			idx = idx.substr(1);
			if(idx.indexOf(",") !== -1){
				Feng.info("请选择单条数据！");
				return false;
			}
			var index = layer.open({type: 2,title: '转为劳保局入款',area: ['600px', '400px'],fix: false, maxmin: true,content: Feng.ctxPath + '/stepfive/status?id='+idx});
			this.layerIndex = index;
		}
	}

	CodeGoods.update = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '修改',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Record.Customer/update?id='+value});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '修改',area: ['100', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Record.Customer/update?id='+idx});
				this.layerIndex = index;
			}
		}
	}


	CodeGoods.delete = function (value) {
		if(value){
			Feng.confirm("是否删除选中项？", function () {
				var ajax = new $ax(Feng.ctxPath + "/Record.Customer/delete", function (data) {
					if ('00' === data.status) {
						Feng.success(data.msg);
						CodeGoods.table.refresh();
					} else {
						Feng.error(data.msg);
					}
				});
				ajax.set('ids', value);
				ajax.start();
			});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				Feng.confirm("是否删除选中项？", function () {
					var ajax = new $ax(Feng.ctxPath + "/Record.Customer/delete", function (data) {
						if ('00' === data.status) {
							Feng.success(data.msg);
							CodeGoods.table.refresh();
						} else {
							Feng.error(data.msg);
						}
					});
					ajax.set('ids', idx);
					ajax.start();
				});
			}
		}
	}


	CodeGoods.qingkuan = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '请款单',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/income/qingKuan?id='+value});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '请款单',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/income/qingKuan?id='+idx});
				this.layerIndex = index;
			}
		}
	}

	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	CodeGoods.export = function (value) {
		if (this.check()) {
			var idx = '';
			$.each(CodeGoods.seItem, function() {
				idx += ',' + this.id;
			});
			idx = idx.substr(1);
			var url="{:url('admin/income/batchExport')}";
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
			$.ajax({
				url:url,
				type:'post',
				data:{idx:idx},
				dataType:'json',
				success:function(result,status,xhr){
					if(result.status==0){
						layer.close(index)
                        var file_path=result.msg.file_path;
                        window.location.href="/download/data/"+file_path;
						// layer.msg('结算成功');
						// CodeGoods.search();
					}else{
						layer.close(index)
						layer.msg('请求失败');
					}
				},
				error:function(result,status,xhr){
					layer.close(index);
					layer.msg('请求出错');
				}
			})
		}
	}


	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/income/index"+url,defaultColunms,500);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});
</script>
{/block}
